package org.example;

import com.sun.corba.se.spi.ior.IORTemplate;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * Hello world!
 *
 */
public class App{
    public static void main(String[] args) {
        Object s1 = new Student("ailun", 21, "男", "168");
        String[] allFieldNames = getAllFieldNames(s1);
    }
    public static String[] getAllFieldNames(Object s1){
        Class clazz = s1.getClass();
        List<Field> fieldList = new ArrayList<>();
        while (clazz != null){
            fieldList.addAll(0,new ArrayList<>(Arrays.asList(clazz.getDeclaredFields())));
            clazz = clazz.getSuperclass();
        }
        List<String> list = new ArrayList<>();
        fieldList.forEach(each -> {
            String name = each.getName();
            list.add(name);
        });
        String[] str = new String[list.size()];
        list.toArray(str);
        return str;
    }
}

//name age
class Person{
    private String name;
    public int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

//sex height
class Student extends Person{
    private String sex;
    private String height;

    public Student() {
    }

    public Student(String name, int age, String sex, String height) {
        super(name, age);
        this.sex = sex;
        this.height = height;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getHeight() {
        return height;
    }

    public void setHeight(String height) {
        this.height = height;
    }
}
